<template>
  <div>
    <page-list :x-uri="uri" :doactions="doactions" :custom-components="customComponents" :search-custom-components="searchCustomComponents" :checkbox-item="false">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs />
      </template>
      <!-- 页面操作按钮 -->
      <template v-slot:page-button>
        <el-button v-auth="'exam.question.topic.create'" size="mini" type="primary" @click="create">新建题目</el-button>
      </template>
      <!-- 多选操作 -->
      <!--    <template v-slot:table-button="scope">
      <el-button size="mini" @click="deletes(scope)" v-auth="'exam.question.topic.delete'">删除</el-button>
    </template> -->
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Tabs from './tabs';
import Title from './components/title.vue';
import LinkPaper from './components/link_info.vue';
import SearchBank from '../bank/SearchBank/index.vue';
export default {
  components: {
    PageList,
    Tabs
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/exam/admin/question/topic/list',
      customComponents: {
        title: Title,
        num: LinkPaper
      },
      doactions: [
        { title: '详情', meta: { permission: 'exam.question.topic.list' }, callback: this.info },
        { title: '编辑', meta: { permission: 'exam.question.topic.edit' }, callback: this.edit },
        { title: '删除', meta: { permission: 'exam.question.topic.delete' }, callback: this.delete }
      ],
      dialogVisible: true,
      searchCustomComponents: {
        bank: SearchBank
      }
    };
  },
  methods: {
    // 新建
    create: function() {
      this.$router.push({ path: '/exam/question/topic/create' });
    },
    // 详情
    info: function({ row }) {
      this.$router.push({ path: '/exam/question/topic/' + row.id + '/details' });
    },
    // 编辑
    edit: function({ row }) {
      this.$router.push({ path: '/exam/question/topic/' + row.id + '/edit' });
    },
    // 删除
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/exam/admin/question/topic/' + row.id + '/delete',
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
    // 批量删除试题
    // deletes: function({ rows }) {
    //   var ids = rows.map(row => row.id);
    //   if (ids.length === 0) {
    //     this.$message.warning('请选择要删除的试题');
    //     return false;
    //   }
    //   ids = ids.join(',');
    //   this.$box
    //     .confirm('确认删除吗')
    //     .then(() => {
    //       this.$http.delete(
    //         '/course/admin/question/topic/deletes/' + ids,
    //         {},
    //         response => {
    //           this.$message.success(response.msg, _ => {
    //             this.reload();
    //           });
    //         },
    //         error => {
    //           this.$message.error(error.msg);
    //         }
    //       );
    //     })
    //     .catch(() => {});
    // }
  }
};
</script>
